import { getCommonDic } from '@/api/login'
const state = {
  dict: new Array()
}
const mutations = {
  SET_DICT: (state, dict) => {
    state.dict = dict
  },
  CLEAN_DICT: (state) => {
    state.dict = new Array()
  }
}

const actions = {
  // 获取字典
  getDict({ commit }) {
    return new Promise((resolve, reject) => {
      getCommonDic().then(res => {
        const resData = res.data;
        commit('SET_DICT', resData)
        resolve(res)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // 清空字典
  cleanDict({ commit }) {
    commit('CLEAN_DICT')
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

